package frame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.KeyStroke;
//创建一个包含菜单栏和主界面的学生成绩管理系统
//StudentScendpanel对象，用于显示学生管理界面。
//两个Action对象student和score，分别用于表示学生管理和成绩查询两个操作

public class StudentMainFrame extends JFrame {
    StudentScendpanel studentScendpanel;
    CommonPanel currentPanel;
    private Action student = new AbstractAction("学生管理", new ImageIcon("images[表情]le.gif")) {
        public void actionPerformed(ActionEvent e) {
            changePanel(studentScendpanel);
        }
    };
    private Action score = new AbstractAction("成绩查询", new ImageIcon("images[表情]le.gif")) {
        public void actionPerformed(ActionEvent e) {
            changePanel(studentScendpanel);
        }

    };

    public static void main(String[] args) {
        // 创建学生管理系统界面
        StudentMainFrame frame = new StudentMainFrame("123456");

    }

    public StudentMainFrame(String sno) {
            this.studentScendpanel = new StudentScendpanel(sno);
            JMenuBar menuBar = new JMenuBar();
//        JMenu menu1 = new JMenu("基础设置");
            JMenu menu2 = new JMenu("成绩查看");
//        menuBar.add(menu1);
            menuBar.add(menu2);

//        menu1.add(student).setAccelerator(KeyStroke.getKeyStroke('s', InputEvent.CTRL_MASK));
            menu2.add(score).setAccelerator(KeyStroke.getKeyStroke('a', InputEvent.CTRL_MASK));
            //让界面作为第一显示界面
            this.add(studentScendpanel);
            this.currentPanel = studentScendpanel;

            this.setJMenuBar(menuBar);
            this.setTitle("学生成绩管理系统");
           // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
            this.setSize(1100, 650);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }

        //切换各个界面
        private void changePanel (CommonPanel commonPanel){
            //移除当前显示的JPanel
            this.remove(currentPanel);
            //添加需要显示的JPanel
            this.add(commonPanel);
            //设置当前的JPanel
            this.currentPanel = commonPanel;
            this.repaint();
            this.setVisible(true);
            //重新读取数据
            commonPanel.setViewDatas();
            //刷新列表
            commonPanel.clear();
        }

    }

